package ModelLayer;
import java.util.ArrayList;

public class OrderContainer
{
    public ArrayList<Order> orderContainer;
    public static OrderContainer instance;
    public OrderContainer()
    {
         orderContainer = new ArrayList<Order>();
    }
    public static OrderContainer getInstance()
    {
        if(instance == null)
        {
            instance = new OrderContainer();
        }
        return instance;
    }
    public void addOrder(Order order)
    {
        orderContainer.add(order);
    }
    public void createOrder(Customer customer, Specimen specimen, Staff staff, int orderID)
    {
        Order order = new Order(customer, specimen, staff, orderID);
        orderContainer.add(order);
    }
    
    public Order findOrder(String phone)
    {
       Order order = null;
       int index = 0;
       boolean found = false;
       while(index < orderContainer.size() && !found)
       {
           order = orderContainer.get(index);
           Customer customer = order.getCustomer();
           if(customer.getPhoneNo().equals(phone))
           {
               found = true;
           }
           else
           {
               index++;
           }
       }
       return orderContainer.get(index);
    }
    public ArrayList<Order> findAllOrders(String phone)
    {
        ArrayList<Order> foundOrder = new ArrayList<Order>();
        for (Order order : orderContainer)
        {
            Customer customer = order.getCustomer();
            if(customer.getPhoneNo().equals(phone))
            {
                foundOrder.add(order);
            }
        } 
        return foundOrder;
    }
    
    public void deleteOrder(int id)
    {
        int index = 0;
        boolean found = false;
        while(index < orderContainer.size() && !found)
        {
            if(orderContainer.get(index).getOrderID() == id)
            {
                orderContainer.remove(index);
                found = true;
            }
            else
            {
                index++;
            }
        }
    }
    public ArrayList<Order> listAllOrders()
    {
        return orderContainer;
    }
}
